<?php

namespace App\Resource;

use App\Model\AgentOrder;
use App\Traits\ResourceWith;
use Hyperf\Resource\Json\JsonResource;

class UserBaseResource extends JsonResource
{
    use ResourceWith;
    /**
     * Transform the resource into an array.
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'nick_name' => $this->nick_name,
            'avatar' => $this->avatar,
            'invite_code' => $this->invite_code,
            'mobile' => $this->mobile,
            'sex' => $this->sex,
            'delay_at' => $this->delay_at,
            'created_at' => $this->created_at->format('Y-m-d H:i:s'),
            'is_agent' => AgentOrder::where('uid', $this->id)->exists()
        ];
    }
}
